//
//  HOUserInfoEntity.m
//  WeiDu_1_0
//
//  Created by foguo-mac-1 on 01/07/16.
//  Copyright (c) 2016 WeiDu Energy Tech. All rights reserved.
//

#import "HOUserInfoEntity.h"
#import "HOConstants.h"
#import "HOUtils.h"

@implementation HOUserInfoEntity
@synthesize		userType;//int型，1:院领导,2:报修人员,3:维修人员；
@synthesize		name;
@synthesize		telPhone;
@synthesize		city;//位置信息
@synthesize		regionId;//int 型，城市索引信息
@synthesize		province; //保留
@synthesize		appraise;//int 型，综合评分值，取整；
@synthesize		gender;//int 型，0：男； 1： 女；
@synthesize		personalIntroduce;//简介，限定字数300；
@synthesize		companyIntroduce;
@synthesize		userIconUrl;//头像的url
@synthesize		userId;
@synthesize		transLevel;//0：未审核； 1：审核中 2: 审核通过；3, 审核不通过
@synthesize		companyName; //String, 企业名称; 翻译师专属信息； 如果角色为企业用户，则为””
@synthesize		balanceAvaiable;//浮点型，，美元为单位，可使用金额
@synthesize		balanceFrozen;//浮点型，美元为单位，冻结金额
@synthesize		language;//“1-2-3”,翻译语言;1:中文，2：日文；3英文
@synthesize		birthday;//字符串型，年龄信息
@synthesize		education;//学历信息
@synthesize		bankAccount;//银行账户信息，纯数字的字符串
@synthesize		bank;//银行账户信息，纯数字的字符串
@synthesize		price;
@synthesize		level;
@synthesize		rating;
@synthesize		todoFillInfo;
@synthesize     isGotInfo;
@synthesize		payStatus;
@synthesize     listId;
@synthesize     orderId;

@synthesize     mobile;
@synthesize     workId;
@synthesize     userName;
@synthesize     email;
@synthesize     headPic;
@synthesize     realName;
@synthesize     departmentName;
@synthesize     jobName;
@synthesize     speed;
@synthesize     praise;
@synthesize     repair;
@synthesize 	workNums;
@synthesize 	acceptedTotalCount;
@synthesize 	unacceptTotalCount;


- (instancetype)init
{
	self = [super init];
	if(self)
	{
		self.name = @"";
		self.telPhone = @"";
		self.city = @"";
		self.province = @"";
		self.companyName = @"";
		self.userIconUrl = @"";
		
		self.companyName = @"";
		self.bankAccount = @"";
		self.bankAccount = @"";
		self.birthday = @"";
		self.birthday = @"";
		self.bank = @"";
		self.userType = [self getType];
	}
	return self;
}



- (BOOL)isLeaderUser
{
	return self.userType == HO_USER_TYPE_LEADER;
}
- (BOOL)isReportUser
{
	return self.userType == HO_USER_TYPE_REPORTER;
}
- (BOOL)isRepairUser
{
	return self.userType == HO_USER_TYPE_REPAIRER;
}

- (void)saveUserId:(int)Id
{
	self.userId = Id;
	NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
	[userDefaults setObject:[NSNumber numberWithInt:self.userId] forKey:kHO_FIELD_UserId];
	[userDefaults synchronize];
	
}

- (int)getUserId
{
	if(self.userId == 0)
	{
		NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
		self.userId = [[userDefaults objectForKey:kHO_FIELD_UserId] intValue];
	}
	return self.userId;
}

- (void)parseDic:(NSDictionary *)dic
{
	if(![self isValidatedDic:dic])
		return;
//	self.isGotData = YES;
	
	self.email = [HOUtils getValideString:[dic objectForKey:kHO_FIELD_Email]];
	self.userId = [[HOUtils getValideString:[dic objectForKey:kHO_FIELD_UserId]] intValue];
	self.mobile = [HOUtils getValideString:[dic objectForKey:kHO_FIELD_Mobile]];
	self.headPic = [HOUtils getValideString:[dic objectForKey:kHO_FIELD_Headpic]];
	self.realName = [HOUtils getValideString:[dic objectForKey:kHO_FIELD_TrueName]];
	self.departmentName = [HOUtils getValideString:[dic objectForKey:kHO_FIELD_DepName]];
	self.jobName = [HOUtils getValideString:[dic objectForKey:kHO_FIELD_JobName]];
	self.workNums = [[HOUtils getValideString:[dic objectForKey:kHO_FIELD_WorkNums]] intValue];
	self.speed = [HOUtils getValideString:[dic objectForKey:kHO_FIELD_Speed]];
	self.praise = [HOUtils getValideString:[dic objectForKey:kHO_FIELD_Praise]];
	self.userType = [[HOUtils getValideString:[dic objectForKey:kHO_FIELD_UserType]] intValue];
	self.repair = [HOUtils getValideString:[dic objectForKey:kHO_FIELD_Repair]];
	self.unhandleReportNumber = [[HOUtils getValideString:[dic objectForKey:kHO_FIELD_Untreated]] intValue];
	self.acceptedTotalCount = [[HOUtils getValideString:[dic objectForKey:kHO_FIELD_AcceptedTotalCount]] intValue];
	self.unacceptedAssistantTotalCount = [[HOUtils getValideString:[dic objectForKey:kHO_FIELD_UnacceptAssistantTotalCount]] intValue];
	self.isDean = [[HOUtils getValideString:[dic objectForKey:kHO_FIELD_isDean]] boolValue];
	
	self.needShowAddExtraBtn = [[HOUtils getValideString:[dic objectForKey:kHO_FIELD_ShowExternal]] boolValue];
	
	self.unacceptTotalCount = [[HOUtils getValideString:[dic objectForKey:kHO_FIELD_UnacceptTotalCount]] intValue];
	self.acceptAssistantTotalCount = [[HOUtils getValideString:[dic objectForKey:kHO_FIELD_AcceptAssistantTotalCount]] intValue];
	self.departmentId = [[HOUtils getValideString:[dic objectForKey:kHO_FIELD_DepartmentId]] intValue];
	self.companyId = [HOUtils getValideString:[dic objectForKey:kHO_FIELD_CompanyID]];
	[self saveCompanyId];
	self.isWorking = [[HOUtils getValideString:[dic objectForKey:kHO_FIELD_WorkStatus]] intValue] == 1; //1在线，2离线;
	
	self.virtualCellPhone = [HOUtils getValideString:[dic objectForKey:kHO_FIELD_VirtualCellPhone]];

}

- (void)saveCompanyId
{
	NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
	[userDefault setObject:self.companyId forKey:kHO_FIELD_CompanyID];
	[userDefault synchronize];
}

- (void)saveType:(HO_USER_TYPE)type
{
	self.userType = type;
	NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
	[userDefaults setObject:[NSNumber numberWithInt:self.userType] forKey:kHO_FIELD_UserType];
	[userDefaults synchronize];
}

- (HO_USER_TYPE)getType
{
	
	NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
	return [[userDefaults objectForKey:kHO_FIELD_UserType] intValue];
}

//- (void)parseDic:(NSDictionary *)dic
//{
//	
//	self.departmentName = [dic objectForKey:kHO_FIELD_DepName];
//	self.email = [dic objectForKey:kHO_FIELD_Email];
//	self.headPic = [dic objectForKey:kHO_FIELD_Headpic];
//	self.jobName = [dic objectForKey:kHO_FIELD_JobName];
//	self.mobile = [dic objectForKey:kHO_FIELD_Mobile];
//	self.praise = [dic objectForKey:kHO_FIELD_Praise];
//	self.repair = [dic objectForKey:kHO_FIELD_Repair];
//	self.speed = [dic objectForKey:kHO_FIELD_Speed];
//	self.realName = [dic objectForKey:kHO_FIELD_TrueName];
//	self.workNums = [[dic objectForKey:kHO_FIELD_WorkNums] intValue];
////	self.departmentName = [dic objectForKey:kHO_FIELD_DepName];
////	self.departmentName = [dic objectForKey:kHO_FIELD_DepName];
////	self.departmentName = [dic objectForKey:kHO_FIELD_DepName];
//	self.workId = [dic objectForKey:kHO_FIELD_WorkeId];
//	
////	
////	DepName = "\U533b\U9662\U529e\U516c\U5ba4";
////	Email = "11176081@qq.com";
////	Headpic = "";
////	JobName = "\U79d1\U5458";
////	Mobile = 18962168530;
////	Praise = "0%";
////	Repair = "0%";
////	Speed = 0min;
////	TrueName = "\U674e\U767d";
////	UserId = 15;
////	UserName = 101111;
////	WorkNum = 0;
////	WorkeId = 100001;
//}

- (void)cleanup
{
	
	NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
	[userDefaults removeObjectForKey:kHO_FIELD_UserId];
	[userDefaults removeObjectForKey:kHO_FIELD_UserType];
	self.isGotData = NO;
	self.name = nil;
	self.telPhone = nil;
	self.city = nil;
	self.province = nil;
	self.companyName = nil;
	self.userIconUrl = nil;
    self.companyId = nil;
    
	
	self.email = nil;
	self.mobile = nil;
	self.headPic = nil;
	self.realName = nil;
	self.departmentName = nil;
	self.jobName = nil;
	self.speed = nil;
	self.praise = nil;
	self.repair = nil;
	
	self.companyName = nil;
	self.bankAccount = nil;
	self.bankAccount = nil;
	self.birthday = nil;
	self.birthday = nil;
	self.bank = nil;
	self.email = nil;
	self.mobile = nil;
	self.headPic = nil;
	self.realName = nil;
	self.departmentName = nil;
	self.jobName = nil;
	self.workNums = 0;
	self.speed = nil;
	self.praise = nil;
	self.repair = nil;
	
}
- (void)dealloc
{
	[self cleanup];
	[super dealloc];
}

@end
